#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
	FILE *fp;
	char buf[256];
	int i, j, N, L, mode, flag;

	N = atoi (argv[1]);
	L = atoi (argv[2]);
	mode = atoi (argv[3]);

	int pathway[L][N];

	fp = fopen (argv[4], "r");
	while (fgets (buf, 256, fp))
	{
		for (i = 0; i < L; i++)
		{
			for (j = 0; j < N; j++)
			{
				fscanf (fp, "%d", &pathway[i][j]);
			}
			fgets (buf, 256, fp);
		}

		flag = 0;
		if (mode == 0)
		{
			for (i = 0; i < N; i++)
			{
				for (j = 0; j < L - 4; j++)
				{
					if (pathway[j][i] == 0 && pathway[j + 1][i] == 1 && pathway[j + 2][i] == 1 && pathway[j + 3][i] == 0)
					{
						flag = 1;
						break;
					}
				}
				if (flag)
					break;
			}
		}
		else
		{
			for (i = 0; i < N; i++)
			{
				for (j = 0; j < L - 4; j++)
				{
					if (pathway[j][i] == 1 && pathway[j + 1][i] == 0 && pathway[j + 2][i] == 0 && pathway[j + 3][i] == 1)
					{
						flag = 1;
						break;
					}
				}
				if (flag)
					break;
			}
		}

		if (flag)
		{
			printf ("c candidate pathway\n");
			for (i = 0; i < L; i++)
			{
				for (j = 0; j < N; j++)
				{
					printf ("%d ", pathway[i][j]);
				}
				printf ("\n");
			}
		}
	}
	fclose (fp);
}
